package com.app.service.impl;

import com.app.mapper.TrainEnrollMapper;
import com.app.model.JobFairSceneModel;
import com.app.model.TrainEnrollModel;
import com.app.service.TrainEnrollService;
import com.app.util.StringTool;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TrainEnrollServiceImpl implements TrainEnrollService {

    @Autowired
    TrainEnrollMapper trainEnrollMapper;
    @Override
    public void insert(TrainEnrollModel model) {
        trainEnrollMapper.insert(model);
    }

    @Override
    public void update(TrainEnrollModel model) {
        trainEnrollMapper.updateById(model);
    }

    @Override
    public void delete(int id) {
        trainEnrollMapper.deleteById(id);
    }

    @Override
    public int selectByPhone(TrainEnrollModel model) {
        QueryWrapper<TrainEnrollModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("mobile", model.getMobile());
        int count = trainEnrollMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public List<TrainEnrollModel> getSkillTrainingList(TrainEnrollModel model) {
        QueryWrapper<TrainEnrollModel> queryWrapper = new QueryWrapper<>();
        if(model.getCid()>0)
        {
            queryWrapper.select().eq("cid", model.getCid());
        }
        if(model.getSid()>0)
        {
            queryWrapper.select().eq("sid", model.getSid());
        }
        if(model.getId()>0)
        {
            queryWrapper.select().eq("id", model.getId());
        }
        List<TrainEnrollModel> userList = trainEnrollMapper.selectList(queryWrapper);
        if (userList.isEmpty()) {
            return null;
        } else {
            return userList;
        }
    }

    @Override
    public TrainEnrollModel selectByCid(TrainEnrollModel model) {
        QueryWrapper<TrainEnrollModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("cid", model.getCid());
        TrainEnrollModel trainEnrollModel = trainEnrollMapper.selectOne(queryWrapper);
        return trainEnrollModel;
    }

    @Override
    public Page<TrainEnrollModel> getModelList(TrainEnrollModel model) {

        QueryWrapper<TrainEnrollModel> queryWrapper = new QueryWrapper<>();
        if(model!=null)
        {
            if(model.getSid()!=null)
            {
                queryWrapper.eq("sid",model.getSid());
            }
        }
        queryWrapper.orderByDesc("crt_time");
        Page<TrainEnrollModel> page = new Page<>();
        page.setCurrent(model.getPage());
        page.setSize(model.getLimit());
        Page<TrainEnrollModel> jobFairSceneModelPage = trainEnrollMapper.selectPage(page,queryWrapper);
        if (jobFairSceneModelPage==null) {
            return null;
        } else {
            return jobFairSceneModelPage;
        }
    }

    @Override
    public Integer selectCount() {
        return trainEnrollMapper.selectCount(null);
    }

    @Override
    public Page<TrainEnrollModel> registrationList(Integer page1, Integer limit, Integer streetId) {
        Page<TrainEnrollModel> page = new Page<>();
        page.setCurrent(page1);
        page.setSize(limit);
        Page<TrainEnrollModel> jobFairSceneModelPage = trainEnrollMapper.selectPage(page,null);
        if (jobFairSceneModelPage==null) {
            return null;
        } else {
            return jobFairSceneModelPage;
        }
    }

}
